package frontend.registration.controller;

import java.sql.Date;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

import core.address.model.BasicAddress;
import core.profile.model.BasicCredential;
import core.profile.model.BasicProfile;
import frontend.registration.dao.RegisterDao;

public class OwnerRegisterAction {
	
	private String emailId, password, firstname, lastname, reminderemail,conformPassword,mobile,countryname,gender,termsconditions;
	private int usertype;
	private int disabledflag;
	private BasicProfile basicProfile;
	private BasicCredential basicCredential;
	private BasicAddress basicAddress;
	private String passwordError ;
	private String emailError;
	private Date creationdate;

	public BasicAddress getBasicAddress() {
		return basicAddress;
	}

	public void setBasicAddress(BasicAddress basicAddress) {
		this.basicAddress = basicAddress;
	}

	public BasicProfile getBasicProfile() {
		return basicProfile;
	}

	public void setBasicProfile(BasicProfile basicProfile) {
		this.basicProfile = basicProfile;
	}

	public BasicCredential getBasicCredential() {
		return basicCredential;
	}

	public void setBasicCredential(BasicCredential basicCredential) {
		this.basicCredential = basicCredential;
	}

	public String getEmailId() {
		return emailId;
	}

	public void setEmailId(String emailId) {
		this.emailId = emailId;
	}

	public String getReminderemail() {
		return reminderemail;
	}

	public void setReminderemail(String emailId) {
		this.reminderemail = emailId;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getConformPassword() {
		return conformPassword;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public void setConformPassword(String conformPassword) {
		this.conformPassword = conformPassword;
	}

	public String getCountryname() {
		return countryname;
	}

	public void setCountryname(String countryname) {
		this.countryname = countryname;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getTermsconditions() {
		return termsconditions;
	}

	public void setTermsconditions(String termsconditions) {
		this.termsconditions = termsconditions;
	}

	public int getUsertype() {
		return usertype;
	}

	public void setUsertype(int usertype) {
		this.usertype = usertype;
	}

	public int getDisabledflag() {
		return disabledflag;
	}

	public void setDisabledflag(int disabledflag) {
		this.disabledflag = disabledflag;
	}

	public String getPasswordError() {
		return passwordError;
	}

	public void setPasswordError(String passwordError) {
		this.passwordError = passwordError;
	}

	public String getEmailError() {
		return emailError;
	}

	public void setEmailError(String emailError) {
		this.emailError = emailError;
	}

	public Date getCreationdate() {
		return creationdate;
	}

	public void setCreationdate(Date creationdate) {
		this.creationdate = creationdate;
	}

	public String execute() throws Exception {
		
		if(conformPassword.equals(basicCredential.getPassword())){		
			this.basicAddress.setEmail(this.getBasicProfile().getEmailId());
			this.basicCredential.setUserId(this.getBasicProfile().getEmailId());
			this.basicCredential.setPassword(Encript.doEncript(this.getBasicCredential().getPassword()));
			this.basicCredential.setBasicprofile(this.getBasicProfile());
			if (RegisterDao.registerUser(basicCredential,basicProfile,basicAddress)){
				Map<String, Object> session = ActionContext.getContext().getSession();
				session.put("emailId", basicCredential.getUserId());
				session.put("logined","false");
				session.put("uuid",basicProfile.getUuid());
				return "success";
			}
			else{
				this.setEmailError("Email is already Exist");
				return "fail";
			}

		}
		else{
			this.setPasswordError("Password and Conform Password are not match.");
			return "error";
		}
	}
		
}
